﻿//==========================页面加载时JS函数开始===============================
$(function () {
    //输入框显示提示效果，配合CSS运用
    $(".input,.login_input,.textarea").focus(function () {
        $(this).addClass("focus");
    }).blur(function () {
        $(this).removeClass("focus");
    });

    //输入框提示,获取拥有HintTitle,HintInfo属性的对象
    $("[HintTitle],[HintInfo]").focus(function (event) {
        $("*").stop(); //停止所有正在运行的动画
        $("#HintMsg").remove(); //先清除，防止重复出错
        var HintHtml = "<ul id=\"HintMsg\"><li class=\"HintTop\"></li><li class=\"HintInfo\"><b>" + $(this).attr("HintTitle") + "</b>" + $(this).attr("HintInfo") + "</li><li class=\"HintFooter\"></li></ul>"; //设置显示的内容
        var offset = $(this).offset(); //取得事件对象的位置
        $("body").append(HintHtml); //添加节点
        $("#HintMsg").fadeTo(0, 0.85); //对象的透明度
        var HintHeight = $("#HintMsg").height(); //取得容器高度
        $("#HintMsg").css({ "top": offset.top - HintHeight + "px", "left": offset.left + "px" }).fadeIn(500);
    }).blur(function (event) {
        $("#HintMsg").remove(); //删除UL
    });
})
//==========================页面加载时JS函数结束===============================

//===========================系统管理JS函数开始================================

function jsprint(msgtitle, url, msgcss) {
    $("#msgprint").remove();
    var cssname = "";
    switch (msgcss) {
        case "Success":
            cssname = "pcent correct";
            break;
        case "Error":
            cssname = "pcent disable";
            break;
        default:
            cssname = "pcent warning";
            break;
    }
    var str = "<div id=\"msgprint\" class=\"" + cssname + "\">" + msgtitle + "</div>";
    $("body").append(str);
    $("#msgprint").show();
    if (url == "back") {
        sysMain.history.back(-1);
    } else if (url != "") {
        sysMain.location.href = url;
    }
    //3秒后清除提示
    setTimeout(function () {
        $("#msgprint").fadeOut(500);
        //如果动画结束则删除节点
        if (!$("#msgprint").is(":animated")) {
            $("#msgprint").remove();
        }
    }, 3000);
}
//遮罩提示窗口
function jsmsg(w, h, msgtitle, msgbox, url, msgcss) {
    $("#msgdialog").remove();
    var cssname = "";
    switch (msgcss) {
        case "Success":
            cssname = "icon-01";
            break;
        case "Error":
            cssname = "icon-02";
            break;
        default:
            cssname = "icon-03";
            break;
    }
    var str = "<div id='msgdialog' title='" + msgtitle + "'><p class='" + cssname + "'>" + msgbox + "</p></div>";
    $("body").append(str);
    $("#msgdialog").dialog({
        //title: null,
        //show: null,
        bgiframe: true,
        autoOpen: false,
        width: w,
        height: h,
        resizable: false,
        closeOnEscape: true,
        buttons: { "确定": function () { $(this).dialog("close"); } },
        modal: true
    });
    $("#msgdialog").dialog("open");
    if (url == "back") {
        sysMain.history.back(-1);
    } else if (url != "") {
        sysMain.location.href = url;
    }
}
//复选框全选
function CheckAll(obj) {
    try {
        if (obj.innerHTML == "全 选") {
            obj.innerHTML = "取 消";
            $(".checkall input").attr("checked", true);
        }
        else {
            obj.innerHTML = "全 选";
            $(".checkall input").attr("checked", false);
        }
    }
    catch (error) {
    }
}
//失去焦点保存标题
var editing = false;
function save_title(obj, channel_id) {
    editing = false;
    $("td[id=" + $(obj).attr('tid') + "]").addClass("loading");
    $.ajax({
        type: "post",
        url: "../../tools/save_title_ajax.ashx?action=saveChildTitle",
        data: "channel_id=" + channel_id + "&title=" + $(obj).val() + "&id=" + $(obj).attr('tid') + "&random=" + Math.random(),
        success: function (msg) {
            $("td[id=" + $(obj).attr('tid') + "]").removeClass("loading");
            $("td[id=" + $(obj).attr('tid') + "]").html(msg);
        }
    });
}
function save_category_title(obj, channel_id) {
    editing = false;
    var thisid = $(obj).attr("tid");
    var thisdiv = $(obj).parent("div[id='" + thisid + "']");
    var thistd = thisdiv.parent("td");
    thistd.addClass("loading");
    $.ajax({
        type: "post",
        url: "../../tools/save_title_ajax.ashx?action=saveCategoryTitle",
        data: "title=" + $(obj).val() + "&id=" + thisid + "&random=" + Math.random(),
        success: function (msg) {
            thistd.removeClass("loading");
            thisdiv.html(msg);
        }
    });
}
//AJAX修改所属分类
function save_category(obj, channel_id, id) {
    $(obj).parent().addClass("loading");
    $.ajax({
        type: "post",
        url: "../../tools/save_category_ajax.ashx",
        data: "channel_id=" + channel_id + "&to_category_id=" + $(obj).val() + "&id=" + id + "&random=" + Math.random(),
        success: function (msg) {
            $(obj).parent().removeClass("loading");
        }
    });
}
//===========================系统管理JS函数结束================================

//================上传文件JS函数开始，需和jquery.form.js一起使用===============

//单个文件上传
function SingleUpload(repath, uppath, isReview, iswater) {
    var submitUrl = "../../tools/SingleUpload.ashx?ReFilePath=" + repath + "&UpFilePath=" + uppath;
    //判断是否打水印
    if (arguments.length == 4) {
        submitUrl = "../../tools/SingleUpload.ashx?ReFilePath=" + repath + "&UpFilePath=" + uppath + "&IsWater=" + iswater;
    }
    //开始提交
    $("#form1").ajaxSubmit({
        beforeSubmit: function (formData, jqForm, options) {
            //隐藏上传按钮
            $("#" + repath).nextAll(".files").eq(0).hide();
            //显示LOADING图片
            $("#" + repath).nextAll(".uploading").eq(0).show();
        },
        success: function (data, textStatus) {
            if (data.msg == 1) {
                $("#" + repath).val(data.msbox);
            } else {
                alert(data.msbox);
            }
            $("#" + repath).nextAll(".files").eq(0).show();
            $("#" + repath).nextAll(".uploading").eq(0).hide();

            //SDF 添加  开始   ---  上传图片后将预览图显示出来
            if (isReview) {
                $("#imgReview").attr("src", data.msbox);
                $("#trReview").show();
            }
            //SDF 添加  结束
        },
        error: function (data, status, e) {
            alert("上传失败，错误信息：" + e);
            $("#" + repath).nextAll(".files").eq(0).show();
            $("#" + repath).nextAll(".uploading").eq(0).hide();
        },
        url: submitUrl,
        type: "post",
        dataType: "json",
        timeout: 600000
    });
};
//===========================上传文件JS函数结束================================